package com.rrd.dw.utils;

import java.lang.reflect.Field;

public class OutPutUtil {

    public static final String FILED_SPLIT = "\001";

    public static String toTableString(Class oc, Object object) {
        StringBuilder sb = new StringBuilder("");
        Field[] fields = oc.getDeclaredFields();
        for (Field field : fields) {
            try {
                field.setAccessible(true);
                if (field.getGenericType().toString()
                    .startsWith("java.util.List")) {
                    continue;
                }
                sb.append((field.get(object) == null ? "" : field.get(object)))
                    .append(OutPutUtil.FILED_SPLIT);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // 去掉多于的逗号
        if (sb.length() > 1) {
            sb.deleteCharAt(sb.length() - 1);
        }
        return sb.toString();
    }
}
